import logging

import allure
import jsonpath

from utils.request.request_control import RequestControl


def http_extract(case, resp, _all):
    if case['json_extract'] is not None:
        with allure.step('json提取'):
            for key, value in eval(case['json_extract']).items():
                _all[key] = jsonpath.jsonpath(resp.json(), value)[0]


def jdbc_extract(case, _all):
    if case['sql_extract'] is not None:
        with allure.step('jdbc提取'):
            for key, value in eval(case['sql_extract']).items():
                _all[key] = RequestControl(case).jdbc_request(value)